package cn.itcast.gateway;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.context.annotation.Bean;
import org.springframework.core.annotation.Order;
import reactor.core.publisher.Mono;

/**
 * @author 虎哥
 */
@SpringBootApplication
public class GatewayApplication {
    public static void main(String[] args) {
        SpringApplication.run(GatewayApplication.class, args);
    }

    @Bean
    @Order(1)
    public GlobalFilter globalFilter1(){
        return (exchange, chain) -> {
            System.out.println("过滤器1 pre阶段！！ ");
            return chain.filter(exchange).then(
                    Mono.fromRunnable(() -> System.out.println("过滤器1的 post阶段"))
            );
        };
    }
    @Bean
    @Order(2)
    public GlobalFilter globalFilter2(){
        return (exchange, chain) -> {
            System.out.println("过滤器2 pre阶段！！ ");
            return chain.filter(exchange).then(
                    Mono.fromRunnable(() -> System.out.println("过滤器2的 post阶段"))
            );
        };
    }
    @Bean
    @Order(3)
    public GlobalFilter globalFilter3(){
        return (exchange, chain) -> {
            System.out.println("过滤器3 pre阶段！！ ");
            return chain.filter(exchange).then(
                    Mono.fromRunnable(() -> System.out.println("过滤器3的 post阶段"))
            );
        };
    }
}
